#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <queue>

std::queue<int> data_queue;
std::mutex m;
std::condition_variable data_cond;

void producer() {
    for (int i = 0; i < 10; ++i) {
        std::this_thread::sleep_for(std::chrono::milliseconds(200));
        {
            std::lock_guard<std::mutex> lk(m);
            data_queue.push(i);
            std::cout << "Produced: " << i << std::endl;
        }
        data_cond.notify_one();
    }
}

void consumer() {
    while (true) {
        std::unique_lock<std::mutex> lk(m);
        data_cond.wait(lk, []{ return !data_queue.empty(); });
        int data = data_queue.front();
        data_queue.pop();
        lk.unlock();
        std::cout << "Consumed: " << data << std::endl;
    }
}

int main() {
    std::thread producer_thread(producer);
    std::thread consumer_thread(consumer);

    producer_thread.join();
    consumer_thread.join();

    return 0;
}
